﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using UCS.ArtificialInteligence.AI;

namespace UCS.ArtificialInteligence.CitiesProblem.Model
{
    public class City : INotifyPropertyChanged, IProblemState
    {
        #region Attributes and Properties

        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;

                RaisePropertyChanged("Name");
            }
        }

        private ObservableCollection<Border> _cityBorders;
        public ObservableCollection<Border> CityBorders
        {
            get { return _cityBorders; }
            set
            {
                _cityBorders = value;

                RaisePropertyChanged("Borders");
            }
        }

        public IEnumerable<ProblemStateBorder> Borders
        {
            get
            {
                foreach (var border in _cityBorders)
                {
                    yield return new ProblemStateBorder(border.To, border.Distance);
                }
            }
        }

        #endregion

        #region Events

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region Constructors

        public City(string name)
        {
            _name = name;
            _cityBorders = new ObservableCollection<Border>();
        }

        #endregion

        #region Public Methods

        public void AddBorderTo(City to, int distance)
        {
            _cityBorders.Add(new Border(this, to, distance));
        }

        #endregion

        #region Private Methods

        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion
    }
}
